package com.jy.demo.presenter;

import android.os.Handler;

import com.jy.demo.contract.UserInfoContract;
import com.jy.demo.model.UserInfoModel;

public class UserInfoPresenter implements UserInfoContract.Presenter {
    private UserInfoContract.View view;

    public UserInfoPresenter(UserInfoContract.View view) {
        this.view = view;
        view.setPresenter(this);
    }

    @Override
    public void loadUserInfo() {
        final String userId = view.loadUserId();
        view.showLoading();//接口请求前显示loading
        //这里模拟接口请求回调-
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                //模拟接口返回的json，并转换为javaBean
                UserInfoModel userInfoModel = new UserInfoModel();
                if (userId.equals("1000")) {
                    userInfoModel.name = "小鬼";
                    userInfoModel.age = 27;
                    userInfoModel.address = "湖南";
                } else {
                    userInfoModel.name = "大宝";
                    userInfoModel.age = 26;
                    userInfoModel.address = "湖南";
                }
                view.showUserInfo(userInfoModel);
                view.dismissLoading();
            }
        }, 3000);
    }

    @Override
    public void start() {
        loadUserInfo();
    }

}
